package com.pmgames.store.data
{
	import mx.collections.ArrayCollection;

	public class ExtendedArrayCollection extends ArrayCollection
	{
		public function ExtendedArrayCollection(source:Array = null)
		{
			super(source);
		}
		
		public function shuffle():ExtendedArrayCollection
		{ 
			var startIndex:int = 0;
			var endIndex:int = this.length-1;
			
			for (var i:int = endIndex; i>=startIndex; i--) 
			{
				var randomNumber:int = Math.floor(Math.random()*endIndex)+startIndex;
				var tmp:* = this[i];
				this[i] = this[randomNumber];
				this[randomNumber] = tmp;
			}
			return this;
		}
		
		public static function setIndexes(length:int):ExtendedArrayCollection
		{
			var indexList:ExtendedArrayCollection = new ExtendedArrayCollection();
			for(var index:int = 0; index < length; index++)
			{
				indexList.addItem(index);
			}
			return indexList.shuffle();
		}
		
		public function createEmptyArray(length:int):void
		{
			for(var index:int = 0; index < length; index++)
			{
				addItem("");
			}
		}
		
		
		public override function toString():String
		{
			var result:String = "";
			for(var index:int = 0; index < this.length; index++)
			{
				result += this.getItemAt(index);
			}
			return result;
		}
	}
}